﻿using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Swagger;

using LmgCMS.Model;
using LmgCMS.Service;

namespace LmgCMS.Areas.API.Controllers
{
    /// <summary>
    /// 系统设置
    /// </summary>
    [ApiExplorerSettings(GroupName = SwaggerGroupingModel.GROUPNAME_COMM)]
    public class SettingController : BaseController<Setting>
    {
        private readonly ISettingService _settingService;
        public SettingController(ISettingService settingService)
        {
            _settingService = settingService;
        }

        #region AppSettings
        /// <summary>
        /// 获取AppSettings
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult AppSettings()
        {
            var set = _settingService.LoadSetting<ApplicationSettings>();
            if (set == null) set = new ApplicationSettings();
            return Content(set.ToJson());
        }
        /// <summary>
        /// 保存AppSettings
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AppSettings(ApplicationSettings model)
        {
            _settingService.SaveSetting(model);
            return Success("操作成功。");
        }
        #endregion
    }

}
